import request from './index'

// 获取发现页帖子
export function getDiscoverPosts(params = {}) {
  return request({
    url: '/posts/discover',
    method: 'get',
    params: {
      page: 1,
      limit: 20,
      ...params
    }
  })
}

// 获取帖子详情（包含用户信息和图片）
export function getPostDetail(postId) {
  return request({
    url: `/posts/${postId}/detail`,
    method: 'get'
  })
}

// 获取帖子评论
export function getPostComments(postId, params = {}) {
  return request({
    url: `/posts/${postId}/comments`,
    method: 'get',
    params: {
      page: 1,
      limit: 20,
      ...params
    }
  })
}

// 添加评论
export function addComment(postId, data) {
  return request({
    url: `/posts/${postId}/comments`,
    method: 'post',
    data
  })
}

// 点赞帖子
export function likePost(postId) {
  return request({
    url: `/posts/${postId}/like`,
    method: 'post'
  })
}

// 取消点赞帖子
export function unlikePost(postId) {
  return request({
    url: `/posts/${postId}/unlike`,
    method: 'delete'
  })
}

// 收藏帖子
export function collectPost(postId) {
  return request({
    url: `/posts/${postId}/collect`,
    method: 'post'
  })
}

// 取消收藏帖子
export function uncollectPost(postId) {
  return request({
    url: `/posts/${postId}/uncollect`,
    method: 'delete'
  })
}

// 点赞评论
export function likeComment(commentId) {
  return request({
    url: `/comments/${commentId}/like`,
    method: 'post'
  })
}

// 取消点赞评论
export function unlikeComment(commentId) {
  return request({
    url: `/comments/${commentId}/unlike`,
    method: 'delete'
  })
}

// 获取用户帖子列表
export function getUserPosts(userId, params = {}) {
  return request({
    url: `/users/${userId}/posts`,
    method: 'get',
    params: {
      page: 1,
      limit: 20,
      ...params
    }
  })
}

// 获取用户收藏列表
export function getUserCollections(userId, params = {}) {
  return request({
    url: `/users/${userId}/collections`,
    method: 'get',
    params: {
      page: 1,
      limit: 20,
      ...params
    }
  })
}

// 创建帖子
export function createPost(data) {
  return request({
    url: '/posts',
    method: 'post',
    data
  })
}

// 更新帖子
export function updatePost(postId, data) {
  return request({
    url: `/posts/${postId}`,
    method: 'put',
    data
  })
}

// 删除帖子
export function deletePost(postId) {
  return request({
    url: `/posts/${postId}`,
    method: 'delete'
  })
}

// 搜索帖子
export function searchPosts(query, params = {}) {
  return request({
    url: '/posts/search',
    method: 'get',
    params: {
      q: query,
      page: 1,
      limit: 20,
      ...params
    }
  })
}

// 获取热门帖子
export function getHotPosts(params = {}) {
  return request({
    url: '/posts/hot',
    method: 'get',
    params: {
      page: 1,
      limit: 20,
      ...params
    }
  })
}

// 获取推荐帖子
export function getRecommendedPosts(params = {}) {
  return request({
    url: '/posts/recommended',
    method: 'get',
    params: {
      page: 1,
      limit: 20,
      ...params
    }
  })
}